package com.seanLab.dao;

import com.seanLab.domain.Article;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

import java.util.*;

/**
 * Created by ailly on 17-8-26.
 */
@Repository
@Qualifier("fakeArticle")
public class FakeArticleDaoImpl implements ArticleDao{
    private static Map<Integer, Article> fakeArticles;

    static {
        fakeArticles = new HashMap<Integer, Article>() {
            {
//                put(1, new Article(1, "news", "sina", "education", "edu", new ArrayList<String>(Arrays.asList("high school", "university")),
//                        "http://news.chenshi.com/article1.html", "What University is?", "bla bla bla",
//                        new ArrayList<String>(Arrays.asList("img001.jpg", "img002.jpg", "img003.jpg")),
//                        new ArrayList<String>(Arrays.asList("http://news.chenshi.com/img001.jpg", "http://news.chenshi.com/img002.jpg", "http://news.chenshi.com/img003.jpg")),
//                        new ArrayList<String>(Arrays.asList("/storage/img001.jpg", "/storage/img002.jpg", "/storage/img003.jpg")),
//                        new ArrayList<String>(Arrays.asList("major", "student", "college"))
//                        )
//                );
////                put(2, new Article(2, "news", "sina", "sports", "edu", new ArrayList<String>(Arrays.asList("badminton", "WBC")),
//                                "http://news.chenshi.com/article2.html", "BWF world championships 2017", "bla bla bla",
//                                new ArrayList<String>(Arrays.asList("img004.jpg", "img005.jpg", "img006.jpg")),
//                                new ArrayList<String>(Arrays.asList("http://news.chenshi.com/img004.jpg", "http://news.chenshi.com/img005.jpg", "http://news.chenshi.com/img006.jpg")),
//                                new ArrayList<String>(Arrays.asList("/storage/img004.jpg", "/storage/img005.jpg", "/storage/img006.jpg")),
//                                new ArrayList<String>(Arrays.asList("badminton", "lin dan", "lee chong wei"))
//                        )
//                );
            }
        };
    }

    @Override
    public int insertArticle(Article article) {
        this.fakeArticles.put(Integer.parseInt(article.getArticleID()), article);
        return 0;
    }

    @Override
    public int removeArticleById(long id) {
        return 0;
    }

    @Override
    public Article getArticleById(long id) {
        return this.fakeArticles.get(id);
    }

    @Override
    public Collection<Article> getAllArticles() {
        return this.fakeArticles.values();
    }

    @Override
    public int updateArticleById(Article article) {
        //this.fakeArticles.get(Integer.parseInt(article.getArticleID())).setKeywords(article.getKeywords());

        return 0;
    }
}
